import { httpRequest } from "@/utils/https.js"
import {baseUrl} from "@/utils/basic.js"

//获取验证码
export const sendMobileCode = (username) =>
	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=sendMobileCode', {
        username
	},'post')
	
//登录
export const login = (mobile_code,username) =>
	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=login', {
        mobile_code,
		username
	},'post')	
export const loginAuth = (username) =>
	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=login', {
        isTemporary:'temp',
		username
	},'post')	    

//个人中心
export const userIndex = (username) =>
	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=userIndex', {
		username
	},'get')	
//个人信息   
 export const userInfo = (username) =>
 	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=userInfo	', {
 		username
 	},'get')	
//设置信息
 export const saveUserInfo = (data) =>
 	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=saveUserInfo',data,'post')	   

//退出登录
 export const logout = (username) =>
 	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=logout',{
        username
    },'get')	
/* **************************** */	
//存储用户信息	
export const  setAuth = (session_id,username)=>{
	try {
	    uni.setStorageSync('session_id',session_id);
		uni.setStorageSync('username',username);
	} catch (e) {
		
	}
}	
//清除用户信息
export const  clearAuth = ()=>{
	try {
        uni.clearStorageSync();
	} catch (e) {
		
	}
}	
//用户头像
export const  setAuthFace = (face)=>{
	try {
		uni.setStorageSync('face',face);
	} catch (e) {
		
	}
}	
//获取用户信息
export const  getAuth = ()=>{
	let datas = {};
	try {
	   datas.session_id = uni.getStorageSync('session_id');
	   datas.username = uni.getStorageSync('username');
	    datas.face = uni.getStorageSync('face');
	} catch (e) {
	    // error
	}
	return datas
}	

// weChatUser
export const getAuthData = (code) =>
	httpRequest(baseUrl+'index.php?m=api&c=wxapp&a=getAuthData', {
        code,
	},'post')	